package zhoufu.sz.sanxiao_check.presents;

import javax.inject.Inject;

import zhoufu.sz.sanxiao_check.models.BaseModel;
import zhoufu.sz.sanxiao_check.models.CheckItemModel;
import zhoufu.sz.sanxiao_check.net.ModifyActionRepository;
import zhoufu.sz.sanxiao_check.net.RequestHelper;
import zhoufu.sz.sanxiao_check.ui.contract.ModifyActionContract;

/**
 * Created by hyc on 16-8-5.
 * 项目 ： XTSanXiao_V2
 * 开发 ： hyc
 * 时间 ： 16-8-5 上午11:45
 * 功能 ： TODO
 */

public class ModifyActionPresenter implements ModifyActionContract.Presenter {

    private final ModifyActionRepository _repository;
    private ModifyActionContract.View _view;

    @Inject
    public ModifyActionPresenter(ModifyActionRepository repository) {
        super();
        _repository = repository;
    }

    public void bindV(ModifyActionContract.View view) {
        _view = view;
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {
        _repository.onDestory();
    }


    /**
     * 把数据提交到服务端
     *
     * @param itemModel
     */
    @Override
    public void update(CheckItemModel itemModel) {
        _repository.update(itemModel, new RequestHelper.RequestCallBack<BaseModel>() {
            @Override
            public void onPullStart() {
                System.out.println("ModifyActionPresenter.onPullStart");
                _view.pullStart();
            }

            @Override
            public void onPullFailud(Throwable throwable) {
                System.out.println("ModifyActionPresenter throwable.getMessage() = " + throwable.getMessage());
                _view.pullFaild();
            }

            @Override
            public void onPullEnd() {
                System.out.println("ModifyActionPresenter.onPullEnd");
                _view.pullEnd();
            }

            @Override
            public void onPullSuccessed(BaseModel s) {
                System.out.println("ModifyActionPresenter.onPullSuccessed");
                System.out.println("s = [" + s + "]");
                if (s.isSuccess())
                    _view.updateSuccess();
                else {
                    _view.pullFaild();
                }
            }

        });
    }
}
